package com.sdutcm.health_bigdata_demo.service;

import com.sdutcm.health_bigdata_demo.bean.Demand;
import com.sdutcm.health_bigdata_demo.bean.Supply;
import com.sdutcm.health_bigdata_demo.dao.DemandDao;
import com.sdutcm.health_bigdata_demo.dao.SupplyDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author 小浩
 * @date 2018-09-23 09:41
 * @package com.sdutcm.health_bigdata_demo.service
 * @description
 */
@Service
@Transactional
public class SupplyAndDemandService {

    @Autowired
    SupplyDao supplyDao;//供应
    @Autowired
    DemandDao demandDao;//需求量

    //发布需求
    public boolean saveDemand(Demand demand){
        return demandDao.save(demand)!=null?true:false;
    }

    //获取全部需求
    public List getAllDemand(){
        return demandDao.findAll();
    }
    //关键字查询需求
    public List getAllDemandFuzzy(String key){
        return demandDao.findAllByNameLikeOrDescribesLike("%"+key+"%","%"+key+"%");
    }


    //发布供应
    public boolean saveSupply(Supply supply){
        return supplyDao.save(supply)!=null?true:false;
    }

    //获取全部供应
    public List getAllSupply(){
        return supplyDao.findAll();
    }
    //关键字查询供应
    public List getAllSupplyFuzzy(String key){
        return supplyDao.findAllByNameLikeOrDescribesLike("%"+key+"%","%"+key+"%");
    }


}
